package DateTest;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateTest {
	public static final long DAY_1 = 86400000;//一天的毫秒数
	private static SimpleDateFormat format = new SimpleDateFormat(
	"yyyy-MM-dd HH:mm:ss");
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(beforeTime("today"));
		Date date = new Date();
		System.out.println(format.format(date.getTime()));
	}
	public static String beforeTime(String days){
    	Date today = new Date();
		int hour = today.getHours();
		int min = today.getMinutes();
		int sec = today.getSeconds();
		int pass = (hour * 3600 + min * 60 + sec)*1000;
		long start = today.getTime() - (long)pass;
		
		if(days.equals("today")){
			return format.format(start);
		}else if(days.equals("day3")){
			start = start - 2*DAY_1;
		}else if(days.equals("day7")){
			start = start - 6*DAY_1;
		}else if(days.equals("thisweek")){
			Calendar cd = Calendar.getInstance();
			int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1;
			start = start - dayOfWeek*DAY_1;
		}
		return format.format(start);
    }
}
